home *** CD-ROM | disk | FTP | other *** search
- #! /usr/local/bin/perl
- #
- # nets - counts the number of hosts per net. The last input column should
- # be an IP address (see hosts-addr)
- #
- # The names should be absolute (see expand)
- #
- # Copyright (C) 1992, 1993 PUUG - Grupo Portugues de Utilizadores
- # do Sistema UNIX
- # 1992, 1993 FCCN - Fundacao para o Desenvolvimento dos Meios
- # Nacionais de Calculo Cientifico
- #
- # Authors: Jorge Frazao de Oliveira <frazao@puug.pt>
- # Artur Romao <artur@dns.pt>
- #
- # This file is part of the DDT package, Version 2.0.
- #
- # Permission to use, copy, modify, and distribute this software and its
- # documentation for any purpose and without any fee is hereby granted,
- # provided that the above copyright notice appear in all copies. Neither
- # PUUG nor FCCN make any representations about the suitability of this
- # software for any purpose. It is provided "as is" without express or
- # implied warranty.
-
- $[ = 1; # set array base to 1
-
- while (<STDIN>) {
- chop; # strip record separator
- @Field = split(' ', $_);
-
- @address = split(/\./, $Field[$#Field]);
-
- # build the net number, according to its class
- if (($address[1] >= 1) && ($address[1] < 127)) { # class A
- $net{join(".", $address[1], "0.0.0")}++;
- }
- elsif (($address[1] >= 128) && ($address[1] < 192)) { # class B
- $net{join(".", $address[1], $address[2], "0.0")}++;
- }
- elsif (($address[1] >= 192) && ($address[1] < 224)) { # class C
- $net{join(".", $address[1], $address[2], $address[3], "0")}++;
- }
- }
-
- foreach $n (keys %net) {
- printf "%5d %s\n", $net{$n}, $n;
- }
-
-